FROM php:5.6-fpm-alpine

# COPY sources.list   /etc/apt/sources.list
# COPY buster.list   /etc/apt/sources.list.d/


# 已下载的扩展安装包copy到镜像中
WORKDIR /package
COPY package .


RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories 

# Install modules
RUN apk update && apk add --no-cache \
        #freetype-dev \
        #libjpeg-turbo-dev \
        #libpng-dev \
        #libmcrypt-dev \
        ffmpeg  \
        autoconf \
        gcc \
        g++ \
        make \
        libffi-dev \
        openssl-dev \
        pcre-dev \
        zlib-dev \
        bzip2-dev \
        linux-headers \
        m4 \
        nginx \
        nginx-mod-http-echo \
        nginx-mod-http-lua \
    
    && docker-php-ext-install -j$(nproc) sockets \
    && mkdir -p /usr/src/php/ext/redis \
    && curl -L https://github.com/phpredis/phpredis/archive/3.1.6.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
    && echo 'redis' >> /usr/src/php-available-exts \
    && docker-php-ext-install redis \


    && echo "=======> install yaf ..." \
    && cd /package \
    && tar zxvf /package/yaf-2.3.4.tgz \
    && rm -f  /package/yaf-2.3.4.tgz \
    && cd /package/yaf-2.3.4 \ 
    && /usr/local/bin/phpize \
    && ./configure --with-php-config=/usr/local/bin/php-config \ 
    && make \
    && make install \
    && make clean \
    && docker-php-ext-enable yaf \
    && echo 'yaf.environ = dev' >> /usr/local/etc/php/conf.d/docker-php-ext-yaf.ini \


    && echo "========> install mongo ..." \
    && cd /package \
    && tar zxvf /package/mongo-1.6.8.tgz \ 
    && rm -f /package/mongo-1.6.8.tgz \
    && cd /package/mongo-1.6.8 \ 
    && /usr/local/bin/phpize \
    && ./configure --with-php-config=/usr/local/bin/php-config \ 
    && make \
    && make install \
    && make clean \
    && docker-php-ext-enable mongo \


    && echo "=====> install msgpack ..." \
    && cd /package \
    && tar zxvf /package/msgpack-0.5.4.tgz \ 
    && rm -f /package/msgpack-0.5.4.tgz \
    && cd /package/msgpack-0.5.4 \ 
    && /usr/local/bin/phpize \
    && ./configure --with-php-config=/usr/local/bin/php-config \ 
    && make \
    && make install \
    && make clean \
    && docker-php-ext-enable msgpack \


    && echo "=====> cp ffmpeg ..." \
    && mkdir -p /data/bin \
    && cp /usr/bin/ffmpeg /data/bin/ \


    && echo "=====> cp nginx ....." \
    && mkdir /run/nginx \
    && cp /package/api.xiaoniangao.com.conf /etc/nginx/conf.d \
    && cp /package/nginx.conf /etc/nginx \
    && mkdir -p /data/server/mobile/xngyaf \ 
    && cp /package/index.php /data/server/mobile/xngyaf \
    && touch /run/nginx/nginx.pid \
    && rm -f /etc/nginx/conf.d/default.conf \
    && mkdir -p /data/server/logs_tmp/nginx_logs \
    && mkdir -p /data/server/logs_tmp/nginx_logs/mini_front_end_log \


    && echo "======> cp shell ......" \
    && cp /package/entrypoint.sh /etc \
    && chmod +x /etc/entrypoint.sh \


    && echo "=====> cp php ......" \
    && cp /package/php-fpm.conf /usr/local/etc \
    && mkdir -p /usr/local/etc/pool \
    && cp /package/www.conf /usr/local/etc/pool \
    && cp /package/php.ini /usr/local/etc/php \


    && echo "=====> clean and rm ......" \
    && apk del m4 autoconf make gcc g++ linux-headers  zlib-dev bzip2-dev \
    && rm -rf /var/cache/apk/* \
    && rm -rf /package/* 


CMD ["/etc/entrypoint.sh"]